<?php
/**
 * XuYuan Project
 *
 * @package	XueYuan 
 * @author	Jiuchi Team
 * @since	Version 1.0.0
 * @filesource
 */
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Login view
 * @author Wayne Yu
 */
?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
    <?php $this->load->view('common/head');?>
	<!-- Page special css -->
    <link rel="stylesheet" type="text/css" href="/assets/css/mycenter.css">
</head>
<body>
    <div class="navigation">
		<?php $this->load->view('common/navigation');?> 
    </div>
    <div class="wrapper">
        <div class="main-content">
            <div class="main-content-inner">
                <div class="profile-edit-wrapper">
                    <div class="profile-edit-header clearfix">
                        <span><?php echo $userInfo['nickname']?></span><span>&gt&gt编辑圈子信息</span>
                        <a href="<?php echo site_url('mycenter')?>" class="profile-edit-backLink">返回圈子</a>
                    </div>
                    <div class="profile-edit-content">
                        <div class="profile-edit-item bd-top clearfix">
                            <h3>圈子名</h3>
                            <div class="profile-edit-itemContent">
                                <?php echo $userInfo['nickname']?>
                            </div>
                        </div>
                        <div class="profile-edit-item bd-top clearfix">
                            <h3>圈子分类</h3>
                            <div class="profile-edit-itemContent">
                                <?php echo $userInfo['nickname']?>
                            </div>
                        </div>
                        <div class="profile-edit-item bd-top clearfix">
                            <h3>圈子头像</h3>
                            <div id="upAvatar" href="<?php echo site_url('mycenter/uploadImg')?>"  class="profile-edit-itemAvatar profile-avatar fancybox fancybox.iframe">
                                <img src="<?php echo $userInfo['headportrait']?>" class="img-profile-avatar">
                            </div>
                        </div>
                        <div class="profile-edit-item bd-top clearfix">
                            <h3>圈子描述</h3>
                            <div class="profile-edit-itemContent">
                                <?php echo $userInfo['signature']?>
                            </div>
                            <button class="profile-edit-btn">修改</button>
                            <div class="profile-edit-clickContent hidden">
                                <div class="profile-edit-inputWrapper">
                                    <textarea name="" cols="30" rows="5" id="signature"></textarea>
                                </div>
                                <div class="profile-edit-actionWrapper">
                                    <button class="save-btn button" data-tag="signature">保存</button>
                                    <button class="cancel-btn button">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer">
			<?php $this->load->view('common/footer');?>
        </div>
    </div>
    <!-- Page special scripts -->
    <script>
    //点击tab切换子页面
    $(document).ready(function() {
        //点击修改按钮，隐藏对应的原界面和修改按钮，显示修改界面
        $('.profile-edit-btn').click(function() {
            $('.profile-edit-itemContent').eq($('.profile-edit-btn').index(this)).hide();
            $('.profile-edit-btn').eq($('.profile-edit-btn').index(this)).hide();
            $('.profile-edit-clickContent').eq($('.profile-edit-btn').index(this)).show();
        });
        //点击取消按钮，隐藏修改界面，显示原界面和修改按钮
        $('.cancel-btn').click(function() {
            $('.profile-edit-clickContent').eq($('.cancel-btn').index(this)).hide();
            $('.profile-edit-itemContent').eq($('.cancel-btn').index(this)).show();
            $('.profile-edit-btn').eq($('.cancel-btn').index(this)).show();
        });
        //点击保存，上传数据,如果成功，隐藏修改界面。保存数据并显示，
        $('.save-btn').click(function() {
            var tag = this.getAttribute("data-tag");
            ind = $('.save-btn').index(this);
            if (tag == "gender") {
                var obj = document.getElementsByName(tag);
                for (var i = 0; i < obj.length; i++) {
                    if (obj[i].checked) {
                        var val = obj[i].value;
                        $.ajax({
                            type: 'post',
                            url: '<?php echo site_url('mycenter/editPost')?>',
                            data: {
                            	Attribute: "gender",
                                Value: val,
                            },
                            dataType: 'json',
                            success: function(data) {
                                if (data.StatusCode == 200) {
		                            $('.profile-edit-clickContent').eq(ind).hide(); //隐藏修改界面
		                            $('.profile-edit-btn').eq(ind).show(); //显示修改按钮
		                            if (val == 1) {
		                                $("#gender").text("男");
		                                $('.profile-edit-itemContent').eq(ind).show(); //显示修改界面
		                            } else {
		                                $("#gender").text("女");
		                                $('.profile-edit-itemContent').eq(ind).show(); //显示修改界面
		                            }
                                } else if (data.StatusCode == 300) {
		                                $("#msg-block").text("修改失败!");
		                                $.fancybox({
		                                    href: "#msg-block",
		                                });
		                            }
		                        }
		                    });  
                        
                    }
                }
            } else {
                var obj = $("#" + tag);
                var objNew = $('.profile-edit-itemContent').eq(ind);
                var val = obj.val();
                $.ajax({
                    type: 'post',
                    url: '<?php echo site_url('mycenter/editPost')?>',
                    data: {
                    	Attribute: tag,
                        Value: val,
                    },
                    dataType: 'json',
                    success: function(data) {
                        if (data.StatusCode == 200) {
                        	obj.val("");
                            objNew.text(val);
                            $('.profile-edit-clickContent').eq(ind).hide(); //隐藏修改界面
                            $('.profile-edit-btn').eq(ind).show(); //显示修改按钮
                            $('.profile-edit-itemContent').eq(ind).show(); //显示新界面
                        } else if (data.StatusCode == 300) {
                            $("#msg-block").text("修改失败!");
                            $.fancybox({
                                href: "#msg-block",
                            });
                        }
                    }
                });
            }
        });
        $("#upAvatar").fancybox({
                padding: 0,
                autoScale: true,
                width:500,
                scrolling: 'auto',
                closeBtn: true,
                afterClose: function () {
                    location.reload(true);
                    return;
                }
            });

    });
    </script>
</body>
</html>

